def dict_2_obj(params: dict, obj_class: object):
    """
        将字典赋值给相同属性的class，并返回实例
    """
    obj = obj_class()
    if hasattr(obj, '__dict__'):
        obj.__dict__.update(params)
    elif hasattr(obj, '__slots__'):
        for slot in obj.__slots__:
            obj.__setattr__(slot, params.get(slot))
    else:
        raise Exception('dict_2_obj error')

    return obj


def obj_2_dict(obj: object):
    """
        为__slots__生成规定的属性字典
    """
    ret = {}
    if hasattr(obj, 'dict'):
        ret = obj.dict()
    elif hasattr(obj, '__dict__'):
        ret = obj.__dict__
    elif hasattr(obj, '__slots__'):
        ret = {slot: obj.__getattribute__(slot) for slot in obj.__slots__}
    return ret
